const { Controller } = require('egg')
const dayjs = require('dayjs')

class ApiController extends Controller {
  /**
   * @api {get} /report [返乡报备] 数据
   * @apiGroup Report
   * @apiDescription 态势总览-返乡报备数据
   * 
   * @apiSuccessExample {json} Success-Response:
  {
      "code": 0,
      "msg": "success",
      "data": [
          {
            "total": 30, // 累计
            "label": "乡镇1", // 乡镇
            "new": 1, // 当日新增
            "jzgl":0, // 集中隔离
            "jjgl":0 // 居家隔离
          }
      ]
  }
   */
  async report() {
    const { ctx } = this

    const returnData = await this.service.trackData.getData('report')

    ctx.body = {
      code: 0,
      msg: 'success',
      data: returnData,
    }
  }

  /**
   * @api {get} /report/early-warn [返乡报备] 人员预警
   * @apiGroup Report
   * @apiDescription 返乡报备-返乡人员核酸预警
   * 
   * @apiSuccessExample {json} Success-Response:
    {
        "code": 0,
        "msg": "success",
        "data": [
            {
                "personNum": 12, // 返乡人数
                "address": "韭园镇", // 乡镇
                "noCheck": 0 // 未做核酸人数
            }
        ]
    }
   */
  async earlyWarn() {
    const { ctx } = this

    const returnData = await this.service.trackData.getData('hsyj')

    ctx.body = {
      code: 0,
      msg: 'success',
      data: returnData,
    }
  }

  /**
   * @api {get} /report/place-scan [返乡报备] 场所扫码
   * @apiGroup Report
   * @apiDescription 返乡报备-返乡人员场所轨迹
   * 
   * @apiParam {String} [scope=day] 统计范围 day（天）、week（周）、month（月）
   * 
   * @apiSuccessExample {json} Success-Response:
  {
      "code": 0,
      "msg": "success",
      "data": [
          {
              "scanNum": 28, // 扫码次数
              "placeName": "场所名称", // 场所名称
              "placeType": "商业、酒店、餐饮" // 场所类型
          },
      ]
  }
   */
  async hsyjPlaceScan() {
    const { ctx } = this
    const { query } = ctx
    const scope = query.scope || 'day'

    const returnData = await this.service.trackData.getData(`${scope}_hsyj_place_scan`)

    ctx.body = {
      code: 0,
      msg: 'success',
      data: returnData,
    }
  }

  /**
   * @api {get} /report/home-address [返乡报备] 居住地
   * @apiGroup Report
   * @apiDescription 返乡报备-返乡人员居住地分析
   * 
   * @apiParam {String} [scope=day] 统计范围 day（天）、week（周）、month（月）
   * 
   * @apiSuccessExample {json} Success-Response:
  {
      "code": 0,
      "msg": "success",
      "data": [
          {
              "personNum": 23, // 返乡人数
              "address": "练寺镇",// 乡镇名称
              "jjgl": 0, // 居家隔离数
              "jzgl": 0 // 记住隔离数
          },
          {
              "personNum": 12,
              "address": "韭园镇",
              "jjgl": 0,
              "jzgl": 0
          }
      ]
  }
   */
  async homeAddress() {
    const { ctx } = this
    const { query } = ctx
    const scope = query.scope || 'day'

    const returnData = await this.service.trackData.getData(`${scope}_hsyj_home_address`)

    ctx.body = {
      code: 0,
      msg: 'success',
      data: returnData,
    }
  }
}

module.exports = ApiController
